package com.kolon.business.mOI.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mOI.controller.MOIIdeaSuggestionWriteController")
public class MOIIdeaSuggestionWriteController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mOI/mOIIdeaSuggestionWrite.do")
	public ModelAndView controller(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 리턴 URL
		String returnUrl = request.getContextPath() + 
			"/business/mOI/mOI.do";
		// 회원정보 세션
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String userId = (String)userMap.get("userId");
		String userPw = (String)userMap.get("userPw");
		String cpyCD = (String)userMap.get("CompanyCD");
		String txtTitle = ComUtil.nullChk(request.getParameter("txtTitle"), "");
		String htmlbody = ComUtil.nullChk(request.getParameter("htmlbody"), "");
		String JudgeDeptCode = ComUtil.nullChk(request.getParameter("JudgeDeptCode"), (String)userMap.get("DeptCode"));
		String radiobutton = ComUtil.nullChk(request.getParameter("radiobutton"), "1");
		String chkSecurity = ComUtil.nullChk(request.getParameter("chkSecurity"), "1");
		// XML DOCUMENT 및 인증 처리
		StringBuffer buffer = new StringBuffer();
		buffer.append(url);
		buffer.append("/oi_suggestion.aspx?strGubun=ideaReg&mode=input");
		buffer.append("&txtTitle=").append(ComUtil.getEncode(txtTitle, "EUC-KR"));
		buffer.append("&htmlbody=").append(ComUtil.getEncode(htmlbody, "EUC-KR"));
		buffer.append("&file=");
		buffer.append("&radiobutton=").append(radiobutton);
		buffer.append("&SaveFlag=").append("R");
		buffer.append("&JudgeDeptCode=").append(JudgeDeptCode);
		buffer.append("&chkSecurity=").append(chkSecurity);
		buffer.append("&pubSubjBaseSeq=");
		buffer.append("&companycd=").append(cpyCD);
		ComUtil.getDocument(buffer.toString(), userId, userPw);
		// 리턴
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("message", "등록되었습니다.");
		modelAndView.addObject("scriptType", "003");
		modelAndView.addObject("message_url", returnUrl);
		modelAndView.setViewName("/business/common/alert");
		return modelAndView;
	}

}
